home *** CD-ROM | disk | FTP | other *** search
/ Linux Cubed Series 8: LINUX Games / Linux Cubed Series 8 - LINUX Games.iso / games / x11 / rpg / crossfir.92 / crossfir / crossfire-0.92.5 / common / info.c < prev    next >
C/C++ Source or Header  |  1996-07-24  |  4KB  |  119 lines

  1. /*
  2.  * static char *rcsid_info_c =
  3.  *    "$Id: info.c,v 1.10 1996/03/04 09:13:04 master Exp $";
  4.  */
  5.  
  6. /*
  7.     CrossFire, A Multiplayer game for X-windows
  8.  
  9.     Copyright (C) 1992 Frank Tore Johansen
  10.  
  11.     This program is free software; you can redistribute it and/or modify
  12.     it under the terms of the GNU General Public License as published by
  13.     the Free Software Foundation; either version 2 of the License, or
  14.     (at your option) any later version.
  15.  
  16.     This program is distributed in the hope that it will be useful,
  17.     but WITHOUT ANY WARRANTY; without even the implied warranty of
  18.     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  19.     GNU General Public License for more details.
  20.  
  21.     You should have received a copy of the GNU General Public License
  22.     along with this program; if not, write to the Free Software
  23.     Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  24.  
  25.     The author can be reached via e-mail to frankj@ifi.uio.no.
  26. */
  27.  
  28. #include <global.h>
  29.  
  30. /*
  31.  * The functions in this file are purely mean to generate information
  32.  * in differently formatted output, mainly about monsters.
  33.  */
  34.  
  35. /*
  36.  * Dump to standard out the abilities of all monsters.
  37.  */
  38.  
  39. void dump_abilities() {
  40.   archetype *at;
  41.   for(at = first_archetype; at; at=at->next) {
  42.     char *ch, *gen_name = "";
  43.     archetype *gen;
  44.  
  45.     if(!QUERY_FLAG(&at->clone,FLAG_MONSTER))
  46.       continue;
  47.  
  48.     /* Get rid of e.g. multiple black puddings */
  49.     if (QUERY_FLAG(&at->clone,FLAG_CHANGING))
  50.       continue;
  51.  
  52.     for (gen = first_archetype; gen; gen = gen->next) {
  53.       if (gen->clone.other_arch && gen->clone.other_arch == at) {
  54.         gen_name = gen->name;
  55.     break;
  56.       }
  57.     }
  58.  
  59.     ch = describe_item(&at->clone);
  60.     printf("%-16s|%6d|%4d|%3d|%s|%s|%s\n",at->clone.name,at->clone.stats.exp,
  61.            at->clone.stats.hp,at->clone.stats.ac,ch,at->name,gen_name);
  62.   }
  63. }
  64.  
  65. /*
  66.  * As dump_abilities(), but with an alternative way of output.
  67.  */
  68.  
  69. void print_monsters() {
  70.   archetype *at;
  71.   object *op;
  72.   char   attbuf[32], protbuf[32], immbuf[32], vulnbuf[32];
  73.  
  74.   printf("               |     |   |    |    |      attack       |    protected      |     immune        |    vulnerable     |        |         |\n");
  75.   printf("monster        | hp  |dam| ac | wc |pmf ecw adw gpd ptf|pmf ecw adw gpd ptf|pmf ecw adw gpd ptf|pmf ecw adw gpd ptf|  exp   | new exp |\n");
  76.   printf("---------------------------------------------------------------------------------------------------------------------------------------\n");
  77.   for(at=first_archetype;at!=NULL;at=at->next) {
  78.     op = arch_to_object(at);
  79.     if (QUERY_FLAG(op,FLAG_MONSTER)) {
  80.       bitstostring((long)op->attacktype, NROFATTACKS, attbuf);
  81.       bitstostring((long)op->protected, NROFATTACKS, protbuf);
  82.       bitstostring((long)op->immune, NROFATTACKS, immbuf);
  83.       bitstostring((long)op->vulnerable, NROFATTACKS, vulnbuf);
  84.       printf("%-15s|%5d|%3d|%4d|%4d|%s|%s|%s|%s|%8d|%9d|\n",
  85.         op->arch->name, op->stats.maxhp, op->stats.dam, op->stats.ac,
  86.         op->stats.wc,
  87.         attbuf, protbuf, immbuf, vulnbuf, op->stats.exp, new_exp(op));
  88.     }
  89.     free_object(op);
  90.   }
  91. }
  92.  
  93. /*
  94.  * Writes <num> ones and zeros to the given string based on the
  95.  * <bits> variable.
  96.  */
  97.  
  98. void bitstostring(long bits, int num, char *str)
  99. {
  100.   int   i,j=0;
  101.  
  102.   if (num > 32)
  103.     num = 32;
  104.  
  105.   for (i=0;i<num;i++) {
  106.     if (i && (i%3)==0) {
  107.       str[i+j] = ' ';
  108.       j++;
  109.     }
  110.     if (bits&1)
  111.       str[i+j] = '1';
  112.     else
  113.       str[i+j] = '0';
  114.     bits >>= 1;
  115.   }
  116.   str[i+j] = '\0';
  117.   return;
  118. }
  119.